layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(addUser)",function(data){
    	if($(".upPassword").val() != $(".password").val()){
    		top.layer.msg("俩次密码输入不统一！");
    		return false;
    	}
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post("/admin/user/insert",{
             userName : $(".userName").val(),  //登录名
             userId: $(".userId").val(),  //邮箱
             email: $(".Email").val(),  
             roleId : data.field.roleId, 
             password : $(".upPassword").val()
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("用户添加成功！");
        		 setTimeout(function(){
        	            window.location.href="/admin/user/showuser";
        	        },2000); 
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})